import { getFIndByParentId } from "@/api/dict";
import { createSlice } from "@reduxjs/toolkit";
import { useSelector } from "react-redux";


const dictSlice = createSlice({
    name: 'dict',
    initialState: {
        dictList:[]
    },
    reducers: {
        upDictList(state, { payload }){
            state.dictList = payload;
        }
    }
})
const { upDictList } = dictSlice.actions;
export const getFIndByParentIdAsync = (parentId:number) => {
    return async (dispatch:any) => {
        const result = await getFIndByParentId(parentId);
        dispatch(upDictList(result.data));
    }
}
export const useSelectorDict = ()=> useSelector((state:any)=>state.dict);
  export default dictSlice.reducer;